In [2]:
# get ic decay
from get_data import get_data,bars
from singletrader.processors.cs_processor import CsWinzorize
from singletrader.shared.utility import save_pkl
from singletrader.factorlib import FactorEvaluation,summary_plot
import pandas as pd
import plotly.express as px
from plotly.figure_factory import create_table
import warnings
warnings.filterwarnings('ignore')
In [3]:
data = get_data().dropna() #获取处理好的数据
features = [_f for _f in data.columns if _f not in bars] + ['ep','circulating_market_cap']
bar_data = data[bars]
# bar_data.head()
In [4]:
liquidity_group = data.groupby(level=0).apply(lambda x:pd.qcut(x['amount3M'],3,labels=['low','medium','high'])).droplevel(0)
ep_group = data.groupby(level=0).apply(lambda x:pd.qcut(x['ep'],3,labels=['low','medium','high'])).droplevel(0)
high_liq =(liquidity_group=='high').astype(int)

Tips¶

- 为了确保因子作用方向一致,Long/Short方向选定使用的是全样本中的因子表现,与选定的start_date/end_date无关

summary of all factors¶

In [5]:
# 非行业中性化(全市场)
fe = FactorEvaluation(bar_data=data[bars],factor_data=data[features],freq=12,winzorize=True,standardize=True,industry_neutralize=False)
fe.get_summary(add_shift=0,start_date='2010-01-01',end_date='2022-12-31',base='close',groups=10) # forward_return: 下月收盘-本月收盘
# fe.get_summary(add_shift=0,start_date='2010-01-01',end_date='2022-12-31',universe=high_liq,base='close-open') # forward_return: 下月收盘-下月开盘
start_date:2010-01-01 / end_date:2022-12-31
Out[5]:
skew adjskew distance mom6x3 mom9x3 mom12x3 mom1M mom2M mom3M mom6M turnover3M amount3M stddev_diff stddev ep circulating_market_cap
ic.mean -0.0220 -0.0251 0.0015 0.0014 0.0075 0.0093 -0.0409 -0.0495 -0.0438 -0.0324 -0.0417 -0.0416 -0.0079 -0.0375 0.0111 -0.0104
ic.t-stats -4.5870 -5.4944 0.1332 0.1753 0.8213 0.9784 -4.4306 -4.6343 -4.2191 -3.0323 -3.7078 -4.6622 -1.4904 -3.0344 1.6189 -1.2103
AnnRet_Long 0.0178 0.0397 0.0273 -0.0197 -0.0058 0.0096 0.0257 0.0839 0.0669 0.0645 0.0795 0.1421 -0.0520 0.0493 0.0037 0.1681
AnnRet_short -0.0631 -0.0609 0.0226 -0.0237 -0.0604 -0.0506 -0.1463 -0.1504 -0.1493 -0.1172 -0.1189 -0.1245 -0.0772 -0.1316 -0.0026 -0.0712
AnnRet 0.0809 0.1006 0.0047 0.0040 0.0546 0.0601 0.1719 0.2343 0.2163 0.1817 0.1984 0.2666 0.0252 0.1809 0.0063 0.2393
SR_Long 0.3605 0.8369 0.2515 -0.2561 -0.0554 0.0888 0.2894 0.7633 0.6396 0.5825 0.5317 1.0871 -0.8670 0.3160 0.0492 1.5498
SR_Short -1.2742 -1.3446 0.1808 -0.2369 -0.7717 -0.6149 -1.3972 -1.2327 -1.1876 -0.9617 -1.0610 -1.0314 -1.0832 -1.1026 -0.0193 -0.4851
SR 0.9711 1.2559 0.0219 0.0262 0.3344 0.3499 1.0203 1.1427 1.0630 0.8597 0.8414 1.2636 0.2412 0.7520 0.0427 1.0186
TO_Long 0.8816 0.8821 0.2880 0.5944 0.3709 0.3140 0.8966 0.7022 0.5939 0.4534 0.1791 0.2441 0.9482 0.4880 0.0876 0.1134
TO_Short 0.8872 0.8867 0.4891 0.5175 0.4543 0.3767 0.8619 0.6243 0.5150 0.3687 0.2387 0.1687 0.9489 0.6880 0.1019 0.0497
In [6]:
# 行业中性化(全市场)
fe = FactorEvaluation(bar_data=data[bars],factor_data=data[features],freq=12,winzorize=True,standardize=True,industry_neutralize=True)
fe.get_summary(add_shift=0,start_date='2010-01-01',end_date='2022-12-31',base='close',groups=10)
start_date:2010-01-01 / end_date:2022-12-31
Out[6]:
skew_GN adjskew_GN distance_GN mom6x3_GN mom9x3_GN mom12x3_GN mom1M_GN mom2M_GN mom3M_GN mom6M_GN turnover3M_GN amount3M_GN stddev_diff_GN stddev_GN ep_GN circulating_market_cap_GN
ic.mean -0.0220 -0.0253 0.0087 -0.0008 0.0017 0.0014 -0.0489 -0.0543 -0.0494 -0.0381 -0.0435 -0.0419 -0.0095 -0.0393 0.0047 -0.0102
ic.t-stats -5.2690 -6.3374 0.8678 -0.1349 0.2458 0.1899 -6.2804 -6.0074 -5.5065 -4.2273 -4.6611 -5.4288 -2.1064 -3.5876 0.8465 -1.3894
AnnRet_Long 0.0195 0.0405 0.0569 0.0046 -0.0082 -0.0007 0.0601 0.1153 0.1058 0.1025 0.0968 0.1022 -0.0380 0.0712 0.0282 0.0316
AnnRet_short -0.0641 -0.0678 0.0079 -0.0239 -0.0081 -0.0056 -0.1546 -0.1497 -0.1499 -0.1180 -0.1205 -0.1296 -0.0718 -0.1314 0.0095 -0.0673
AnnRet 0.0836 0.1082 0.0490 0.0285 -0.0000 0.0050 0.2148 0.2650 0.2557 0.2205 0.2173 0.2318 0.0338 0.2026 0.0187 0.0989
SR_Long 0.4508 0.8792 0.6169 0.0740 -0.0901 -0.0068 0.8227 1.2591 1.1921 1.1122 0.8394 1.2873 -0.7439 0.5047 0.4205 0.5792
SR_Short -1.4646 -1.6395 0.0704 -0.2692 -0.1455 -0.1003 -1.6461 -1.3574 -1.3175 -1.0741 -1.1835 -1.1387 -1.1136 -1.2962 0.0846 -0.4884
SR 1.2023 1.5234 0.2644 0.2415 -0.0002 0.0389 1.5427 1.5689 1.4622 1.2298 1.1643 1.4622 0.3679 0.9477 0.1564 0.6612
TO_Long 0.8799 0.8827 0.3010 0.5858 0.3742 0.3151 0.8902 0.6950 0.5860 0.4464 0.2266 0.2160 0.9467 0.5429 0.0966 0.0708
TO_Short 0.8847 0.8857 0.4620 0.5193 0.4472 0.3742 0.8628 0.6252 0.5175 0.3728 0.2423 0.1747 0.9491 0.6948 0.1270 0.0512
In [7]:
# 行业中性化因子(高流动性股票池)
fe = FactorEvaluation(bar_data=data[bars],factor_data=data[features],freq=12,winzorize=True,standardize=True,industry_neutralize=True)
fe.get_summary(add_shift=0,start_date='2010-01-01',universe=high_liq,end_date='2022-12-31',base='close',groups=10) # forward_return: 下月收盘-本月收盘
start_date:2010-01-01 / end_date:2022-12-31
Out[7]:
skew_GN adjskew_GN distance_GN mom6x3_GN mom9x3_GN mom12x3_GN mom1M_GN mom2M_GN mom3M_GN mom6M_GN turnover3M_GN amount3M_GN stddev_diff_GN stddev_GN ep_GN circulating_market_cap_GN
ic.mean -0.0202 -0.0138 -0.0039 0.0175 0.0216 0.0235 -0.0465 -0.0478 -0.0388 -0.0172 -0.0490 -0.0222 0.0032 -0.0304 0.0338 0.0152
ic.t-stats -4.1262 -2.8306 -0.3408 2.0443 2.2881 2.4099 -4.9462 -4.6531 -3.9111 -1.6463 -3.9959 -2.9157 0.5216 -2.5719 3.5621 1.3980
AnnRet_Long 0.0335 0.0316 0.0006 0.0285 0.0437 0.0455 0.0508 0.0890 0.0699 0.0089 0.0644 0.0210 -0.0453 0.0158 0.0513 0.0302
AnnRet_short -0.0637 -0.0364 0.0038 -0.0468 -0.0760 -0.0637 -0.1305 -0.1187 -0.1095 -0.0695 -0.1410 -0.0543 -0.0664 -0.1255 -0.0935 -0.0335
AnnRet 0.0972 0.0680 -0.0032 0.0753 0.1198 0.1092 0.1813 0.2078 0.1793 0.0784 0.2054 0.0753 0.0211 0.1413 0.1448 0.0636
SR_Long 0.5621 0.5633 0.0058 0.2590 0.3798 0.3882 0.5564 0.9252 0.7009 0.0964 0.6539 0.3566 -0.6053 0.1576 0.3437 0.1813
SR_Short -0.9874 -0.7332 0.0325 -0.5949 -0.9123 -0.8294 -1.1598 -1.0005 -0.9607 -0.5559 -1.0915 -0.4948 -0.8550 -1.0657 -1.1397 -0.4800
SR 1.0710 0.7791 -0.0162 0.5075 0.7493 0.6669 1.0583 1.1642 1.0345 0.4262 1.0012 0.5813 0.1785 0.7200 0.8395 0.3384
TO_Long 0.9007 0.9030 0.5709 0.5556 0.4257 0.3718 0.9108 0.7562 0.6381 0.4852 0.2484 0.4582 0.9679 0.6394 0.1977 0.0664
TO_Short 0.8975 0.9011 0.3864 0.6375 0.5266 0.4679 0.8843 0.7150 0.5892 0.4310 0.3276 0.2010 0.9592 0.7263 0.2654 0.2560

details of mom3M¶

收益曲线和表格指标,均是针对超额收益,benchmark用的是equal weighted

In [8]:
factor='mom3M_GN'
report = fe.get_factor_detail_report(factor=factor,add_shift=0,base='close',start_date='2010-01-01',end_date='2022-12-31',total=False,excess_return=True,holding_period=1)
summary_plot(report)
In [9]:
group_ic = fe.factor_ana(factor=factor,ep_group=ep_group,liquidity_group=liquidity_group,add_shift=0,base='close')
bar = px.bar(group_ic['ic.mean'].reset_index(),x='level_1',y='ic.mean',color='level_0',barmode='group',title='ic of different ep & lquidity')
bar.show()
In [ ]: